import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

class MyThreadPool3{
    private BlockingDeque<Runnable> queue = new LinkedBlockingDeque<>();

    static class Worker extends Thread{

        private BlockingDeque<Runnable> queue = null;
        public Worker(BlockingDeque<Runnable> queue){
            this.queue = queue;
        }

        @Override
        public void run() {
            while(true){
                try {
                    Runnable runnable = queue.take();
                    runnable.run();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private List<Thread> workers = new ArrayList<>();

    public MyThreadPool3(int n){
        for (int i = 0; i < n; i++) {
            Worker worker = new Worker(queue);
            worker.start();
            workers.add(worker);
        }
    }

    public  void submit(Runnable runnable) {
            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
}
public class Test3 {
    public static void main(String[] args) {
        MyThreadPool3 pool3 = new MyThreadPool3(6);
        for (int i = 0; i < 6; i++) {
            pool3.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello pool");
                }
            });
        }
    }
}
